<!DOCTYPE html>


<html lang="zh_CN">
  

    <head>
      <meta charset="utf-8" />
        
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
      <title>Zuul路由网关 |  MyBlog</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/favicon.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css"
      />
      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    <link rel="alternate" href="/atom.xml" title="MyBlog" type="application/atom+xml">
</head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="SpringCloud-SpringCloud-Zuul路由网关"
  class="article article-type-SpringCloud"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  Zuul路由网关
</h1>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2022/03/12/SpringCloud-Zuul%E8%B7%AF%E7%94%B1%E7%BD%91%E5%85%B3/" class="article-date">
  <time datetime="2022-03-12T14:28:20.000Z" itemprop="datePublished">2022-03-12</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/SpringCloud/">SpringCloud</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">2.3k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">10 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <p>[TOC]</p>
<h1 id="十一、Zuul路由网关"><a href="#十一、Zuul路由网关" class="headerlink" title="十一、Zuul路由网关"></a>十一、Zuul路由网关</h1><h2 id="11-1-概述"><a href="#11-1-概述" class="headerlink" title="11.1.概述"></a>11.1.概述</h2><h3 id="11-1-1-官网资料"><a href="#11-1-1-官网资料" class="headerlink" title="11.1.1.官网资料"></a>11.1.1.官网资料</h3><p><a target="_blank" rel="noopener" href="https://github.com/Netflix/zuul/wiki/Getting-Started">https://github.com/Netflix/zuul/wiki/Getting-Started</a></p>
<p><a target="_blank" rel="noopener" href="https://docs.spring.io/spring-cloud-netflix/docs/2.2.9.RELEASE/reference/html/#router-and-filter-zuul">https://docs.spring.io/spring-cloud-netflix/docs/2.2.9.RELEASE/reference/html/#router-and-filter-zuul</a></p>
<h3 id="11-1-2-Zuul是什么"><a href="#11-1-2-Zuul是什么" class="headerlink" title="11.1.2.Zuul是什么"></a>11.1.2.Zuul是什么</h3><p>Zuul是一种<strong>提供动态路由、监视、弹性、安全性等功能的边缘服务</strong>。</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051043528.png" alt="image-20220305104301523"></p>
<p>路由是微服务架构的一个组成部分。例如，<code>/</code>可能映射到您的 Web 应用程序、<code>/api/users</code>映射到用户服务和<code>/api/shop</code>映射到商店服务。 <a target="_blank" rel="noopener" href="https://github.com/Netflix/zuul">Zuul</a>是来自 Netflix 的基于 JVM 的路由器和服务器端负载均衡器。</p>
<p>API网关为微服务架构中的服务提供了统一的访问入口，客户端通过API网关访问相关服务。API网关的定义类似于设计模式中的门面模式，它相当于整个微服务架构中的门面，所有客户端的访问都通过它来进行路由及过滤。它实现了请求路由、负载均衡、校验过滤、服务容错、服务聚合等功能。</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051048224.png" alt="image-20220305104800061"></p>
<h3 id="11-1-3-Netflix将Zuul用于以下用途"><a href="#11-1-3-Netflix将Zuul用于以下用途" class="headerlink" title="11.1.3.Netflix将Zuul用于以下用途"></a>11.1.3.Netflix将Zuul用于以下用途</h3><ul>
<li>验证</li>
<li>见解</li>
<li>压力测试</li>
<li>金丝雀测试（灰度发布）</li>
<li>动态路由</li>
<li>服务迁移</li>
<li>减载</li>
<li>安全</li>
<li>静态响应处理</li>
<li>主动流量管理</li>
</ul>
<p>Zuul包含了如下最主要的功能：<br><font color='red'><strong>代理+路由+过滤三大功能</strong></font></p>
<h3 id="11-1-4-负载均衡"><a href="#11-1-4-负载均衡" class="headerlink" title="11.1.4.负载均衡"></a>11.1.4.负载均衡</h3><p>网关为入口，由网关与微服务进行交互，所以网关必须要实现负载均衡的功能；</p>
<p>网关会获取微服务注册中心里面的服务连接地址，再配合一些算法选择其中一个服务地址，进行处理业务。<br>这个属于客户端侧的负载均衡，由调用方去实现负载均衡逻辑。</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051051025.png" alt="image-20220305105154409"></p>
<h3 id="11-1-5-灰度发布"><a href="#11-1-5-灰度发布" class="headerlink" title="11.1.5.灰度发布"></a>11.1.5.灰度发布</h3><p>起源是，矿井工人发现，金丝雀对瓦斯气体很敏感，矿工会在下井之前，先放一只金丝雀到井中，如果金丝雀不叫了，就代表瓦斯浓度高。</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051055329.png" alt="image-20220305105517501"></p>
<p>在灰度发布开始后，<strong>先启动一个新版本应用</strong>，但是并不直接将流量切过来，而是<strong>测试人员对新版本进行线上测试</strong>，启动的这个新版本应用，就是我们的金丝雀。<strong>如果没有问题，那么可以将少量的用户流量导入到新版本上</strong>，然后再对新版本做运行状态观察，收集各种运行时数据，如果此时<strong>对新旧版本做各种数据对比</strong>，就是所谓的A/B测试。新版本<strong>没什么问题，那么逐步扩大范围、流量，把所有用户都迁移到新版本上面来</strong>。</p>
<h2 id="11-2-路由基本配置"><a href="#11-2-路由基本配置" class="headerlink" title="11.2.路由基本配置"></a>11.2.路由基本配置</h2><h3 id="11-2-1-功能"><a href="#11-2-1-功能" class="headerlink" title="11.2.1.功能"></a>11.2.1.功能</h3><p>负责将外部请求转发到具体的服务实例上去，是实现同一访问入口的基础</p>
<h3 id="11-2-2-新建cloud-zuul-gateway9527模块"><a href="#11-2-2-新建cloud-zuul-gateway9527模块" class="headerlink" title="11.2.2.新建cloud-zuul-gateway9527模块"></a>11.2.2.新建cloud-zuul-gateway9527模块</h3><h3 id="11-2-3-修改pom"><a href="#11-2-3-修改pom" class="headerlink" title="11.2.3.修改pom"></a>11.2.3.修改pom</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-netflix-eureka-client<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-netflix-zuul<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-devtools<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">scope</span>&gt;</span>runtime<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">optional</span>&gt;</span>true<span class="tag">&lt;/<span class="name">optional</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.projectlombok<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>lombok<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">optional</span>&gt;</span>true<span class="tag">&lt;/<span class="name">optional</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">scope</span>&gt;</span>test<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="11-2-4-写yml文件"><a href="#11-2-4-写yml文件" class="headerlink" title="11.2.4.写yml文件"></a>11.2.4.写yml文件</h3><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">9527</span></span><br><span class="line"></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">application:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">cloud-zuul-gateway</span></span><br><span class="line"></span><br><span class="line"><span class="attr">eureka:</span></span><br><span class="line">  <span class="attr">client:</span></span><br><span class="line">    <span class="attr">service-url:</span></span><br><span class="line">      <span class="comment">#defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka</span></span><br><span class="line">      <span class="attr">defaultZone:</span> <span class="string">http://eureka7001.com:7001/eureka</span></span><br><span class="line">  <span class="attr">instance:</span></span><br><span class="line">    <span class="attr">instance-id:</span> <span class="string">gateway-9527.com</span></span><br><span class="line">    <span class="attr">prefer-ip-address:</span> <span class="literal">true</span> </span><br></pre></td></tr></table></figure>

<h3 id="11-2-5-系统配置文件hosts修改"><a href="#11-2-5-系统配置文件hosts修改" class="headerlink" title="11.2.5.系统配置文件hosts修改"></a>11.2.5.系统配置文件hosts修改</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">127.0.0.1 myzuul.com</span><br></pre></td></tr></table></figure>

<h3 id="11-2-6-创建启动类"><a href="#11-2-6-创建启动类" class="headerlink" title="11.2.6.创建启动类"></a>11.2.6.创建启动类</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableZuulProxy</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Zuul_9527_StartSpringCloudApp</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        SpringApplication.run(Zuul_9527_StartSpringCloudApp.class, args);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="11-2-7-启动测试"><a href="#11-2-7-启动测试" class="headerlink" title="11.2.7.启动测试"></a>11.2.7.启动测试</h3><p>先启动7001eureka服务注册中心</p>
<p>再启动一个服务提供类cloud-provider-payment8001</p>
<p>启动一个服务网关</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051119936.png" alt="image-20220305111900677"></p>
<blockquote>
<p>测试</p>
</blockquote>
<p>不要路由时访问<a target="_blank" rel="noopener" href="http://localhost:8001/payment/get/8">http://localhost:8001/payment/get/8</a></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051117082.png" alt="image-20220305111707834"></p>
<p>启动路由访问地址<font color='red'><strong><a target="_blank" rel="noopener" href="http://zuul映射配置+注册中心注册后对外暴露的服务名称+rest调用地址/">http://zuul映射配置+注册中心注册后对外暴露的服务名称+rest调用地址</a></strong></font></p>
<p><a target="_blank" rel="noopener" href="http://myzuul.com:9527/cloud-payment-service/payment/get/8">http://myzuul.com:9527/cloud-payment-service/payment/get/8</a></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051118489.png" alt="image-20220305111840130"></p>
<h2 id="11-3-路由访问映射规则"><a href="#11-3-路由访问映射规则" class="headerlink" title="11.3.路由访问映射规则"></a>11.3.路由访问映射规则</h2><h3 id="11-3-1-修改cloud-zuul-gateway9527模块"><a href="#11-3-1-修改cloud-zuul-gateway9527模块" class="headerlink" title="11.3.1.修改cloud-zuul-gateway9527模块"></a>11.3.1.修改cloud-zuul-gateway9527模块</h3><h4 id="1-修改yml"><a href="#1-修改yml" class="headerlink" title="1.修改yml"></a>1.修改yml</h4><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">zuul:</span></span><br><span class="line">  <span class="attr">routes:</span>  <span class="comment">#路由映射配置</span></span><br><span class="line">    <span class="attr">mypayment.path:</span> <span class="string">/mypayment/**</span>   <span class="comment">#浏览器地址栏输入的路径</span></span><br><span class="line">    <span class="attr">mypayment.serviceId:</span> <span class="string">cloud-payment-service</span>  <span class="comment">#对外暴露的微服务名称</span></span><br></pre></td></tr></table></figure>

<p>我们在配置映射规则时会发现它只提醒我们zuul.routes这个属性，这时我们可以去看ZuulProperties</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051143912.png" alt="image-20220305114339748"></p>
<p>它是通过map集合进行配置的</p>
<p>测试：此时无论是自定义的代理名称还是默认的路由规则，都可以访问成功</p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051135960.png" alt="image-20220305113548637"></p>
<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051136684.png" alt="image-20220305113633485"></p>
<h4 id="2-忽略原有真实服务名"><a href="#2-忽略原有真实服务名" class="headerlink" title="2.忽略原有真实服务名"></a>2.忽略原有真实服务名</h4><p>如果我们只希望使用我们自己定义的路由规则，可以通过以下配置忽略默认的</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">zuul:</span></span><br><span class="line">  <span class="attr">ignored-services:</span> <span class="string">cloud-provider-payment</span></span><br><span class="line">  <span class="attr">routes:</span>  <span class="comment">#路由映射配置</span></span><br><span class="line">    <span class="attr">mypayment.path:</span> <span class="string">/mypayment/**</span>   <span class="comment">#浏览器地址栏输入的路径</span></span><br><span class="line">    <span class="attr">mypayment.serviceId:</span> <span class="string">cloud-payment-service</span>  <span class="comment">#对外暴露的微服务名称</span></span><br></pre></td></tr></table></figure>

<p>如果忽略多个默认的路由规则，可以使用*</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">zuul:</span></span><br><span class="line">  <span class="attr">ignored-services:</span> <span class="string">”*“</span></span><br></pre></td></tr></table></figure>

<h3 id="11-3-2-路由转发和负载均衡功能"><a href="#11-3-2-路由转发和负载均衡功能" class="headerlink" title="11.3.2.路由转发和负载均衡功能"></a>11.3.2.路由转发和负载均衡功能</h3><h4 id="1-微服务提供者SMS短信模块"><a href="#1-微服务提供者SMS短信模块" class="headerlink" title="1.微服务提供者SMS短信模块"></a>1.微服务提供者SMS短信模块</h4><h5 id="（1）新建cloud-provider-sms8008模块"><a href="#（1）新建cloud-provider-sms8008模块" class="headerlink" title="（1）新建cloud-provider-sms8008模块"></a>（1）新建cloud-provider-sms8008模块</h5><h5 id="（2）修改pom"><a href="#（2）修改pom" class="headerlink" title="（2）修改pom"></a>（2）修改pom</h5><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.cloud<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-cloud-starter-netflix-eureka-client<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-devtools<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">scope</span>&gt;</span>runtime<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">optional</span>&gt;</span>true<span class="tag">&lt;/<span class="name">optional</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.projectlombok<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>lombok<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">optional</span>&gt;</span>true<span class="tag">&lt;/<span class="name">optional</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">scope</span>&gt;</span>test<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h5 id="（3）写yml"><a href="#（3）写yml" class="headerlink" title="（3）写yml"></a>（3）写yml</h5><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">8008</span></span><br><span class="line"></span><br><span class="line"><span class="comment">###服务名称(服务注册到eureka名称)</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">    <span class="attr">application:</span></span><br><span class="line">        <span class="attr">name:</span> <span class="string">cloud-provider-sms</span></span><br><span class="line"></span><br><span class="line"><span class="attr">eureka:</span></span><br><span class="line">  <span class="attr">client:</span> <span class="comment">#服务提供者provider注册进eureka服务列表内</span></span><br><span class="line">    <span class="attr">service-url:</span></span><br><span class="line">      <span class="attr">register-with-eureka:</span> <span class="literal">true</span></span><br><span class="line">      <span class="attr">fetch-registry:</span> <span class="literal">true</span></span><br><span class="line">      <span class="comment">#defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka</span></span><br><span class="line">      <span class="comment">#defaultZone: http://127.0.0.1:7001/eureka,http://127.0.0.1:7002/eureka</span></span><br><span class="line">      <span class="attr">defaultZone:</span> <span class="string">http://eureka7001.com:7001/eureka</span>   <span class="comment"># eureka集群加@老本版</span></span><br></pre></td></tr></table></figure>

<h5 id="（4）业务类"><a href="#（4）业务类" class="headerlink" title="（4）业务类"></a>（4）业务类</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SMSController</span></span>&#123;</span><br><span class="line">    <span class="meta">@Value(&quot;$&#123;server.port&#125;&quot;)</span></span><br><span class="line">    <span class="keyword">private</span> String serverPort;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@GetMapping(&quot;/sms&quot;)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">sms</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;sms provider service: &quot;</span>+<span class="string">&quot;\t&quot;</span>+serverPort;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h5 id="（5）创建启动类"><a href="#（5）创建启动类" class="headerlink" title="（5）创建启动类"></a>（5）创建启动类</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@EnableEurekaClient</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MainAppSMS8008</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        SpringApplication.run(MainAppSMS8008.class,args);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h5 id="（6）将当前微服务注册进eureka服务器中"><a href="#（6）将当前微服务注册进eureka服务器中" class="headerlink" title="（6）将当前微服务注册进eureka服务器中"></a>（6）将当前微服务注册进eureka服务器中</h5><h4 id="2-修改zuul服务9527模块"><a href="#2-修改zuul服务9527模块" class="headerlink" title="2.修改zuul服务9527模块"></a>2.修改zuul服务9527模块</h4><h5 id="（1）修改yml，体现路由转发和负载均衡"><a href="#（1）修改yml，体现路由转发和负载均衡" class="headerlink" title="（1）修改yml，体现路由转发和负载均衡"></a>（1）修改yml，体现路由转发和负载均衡</h5><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">zuul:</span></span><br><span class="line">  <span class="attr">ignored-services:</span> <span class="string">&quot;*&quot;</span></span><br><span class="line">  <span class="attr">routes:</span>  <span class="comment">#路由映射配置</span></span><br><span class="line">    <span class="attr">mypayment.path:</span> <span class="string">/mypayment/**</span>   <span class="comment">#浏览器地址栏输入的路径</span></span><br><span class="line">    <span class="attr">mypayment.serviceId:</span> <span class="string">cloud-payment-service</span>  <span class="comment">#对外暴露的微服务名称</span></span><br><span class="line">    <span class="attr">mysms.path:</span> <span class="string">/mysms/**</span></span><br><span class="line">    <span class="attr">mysms.serviceId:</span> <span class="string">cloud-provider-sms</span></span><br></pre></td></tr></table></figure>

<p>由于Zuul集成了Ribbon和Hystrix，所以Zuul天生就有负载均衡和服务容错能力</p>
<h5 id="（2）测试"><a href="#（2）测试" class="headerlink" title="（2）测试"></a>（2）测试</h5><p><a target="_blank" rel="noopener" href="http://myzuul.com:9527/mypayment/payment/get/8%E5%AE%9E%E7%8E%B0%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%EF%BC%8C%E5%89%8D%E6%8F%90%EF%BC%9A%E6%9C%89%E5%A4%9A%E5%8F%B0%E6%9C%8D%E5%8A%A1%E5%90%8D%E7%A7%B0%E7%9B%B8%E5%90%8C%E4%B8%94%E6%8B%A5%E6%9C%89%E7%9B%B8%E5%90%8C%E7%9A%84%E6%98%A0%E5%B0%84%E8%B7%AF%E5%BE%84%E5%8F%8A%E5%AF%B9%E5%BA%94%E7%9A%84%E5%A4%84%E7%90%86%E5%99%A8handle">http://myzuul.com:9527/mypayment/payment/get/8实现负载均衡，前提：有多台服务名称相同且拥有相同的映射路径及对应的处理器handle</a></p>
<p><a target="_blank" rel="noopener" href="http://myzuul.com:9527/mysms/sms">http://myzuul.com:9527/mysms/sms</a> 实现路由转发</p>
<h3 id="11-3-3-设置统一的公共前缀"><a href="#11-3-3-设置统一的公共前缀" class="headerlink" title="11.3.3.设置统一的公共前缀"></a>11.3.3.设置统一的公共前缀</h3><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">zuul:</span></span><br><span class="line">  <span class="attr">prefix:</span> <span class="string">/yuan</span></span><br></pre></td></tr></table></figure>

<p>格式：<a target="_blank" rel="noopener" href="http://myzuul.com:9527/%E5%85%AC%E5%91%8A%E5%89%8D%E7%BC%80/%E8%87%AA%E5%AE%9A%E4%B9%89%E8%B7%AF%E7%94%B1%E8%A7%84%E5%88%99/rest%E8%B0%83%E7%94%A8">http://myzuul.com:9527/公告前缀/自定义路由规则/rest调用</a></p>
<h2 id="11-4-查看路由信息"><a href="#11-4-查看路由信息" class="headerlink" title="11.4.查看路由信息"></a>11.4.查看路由信息</h2><h3 id="11-4-1-pom文件中导入actuator依赖"><a href="#11-4-1-pom文件中导入actuator依赖" class="headerlink" title="11.4.1.pom文件中导入actuator依赖"></a>11.4.1.pom文件中导入actuator依赖</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="11-4-2-修改yml"><a href="#11-4-2-修改yml" class="headerlink" title="11.4.2.修改yml"></a>11.4.2.修改yml</h3><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 开启查看路由的端点</span></span><br><span class="line"><span class="attr">management:</span></span><br><span class="line">  <span class="attr">endpoints:</span></span><br><span class="line">    <span class="attr">web:</span></span><br><span class="line">      <span class="attr">exposure:</span></span><br><span class="line">        <span class="attr">include:</span> <span class="string">&#x27;routes&#x27;</span> </span><br></pre></td></tr></table></figure>

<p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051343405.png" alt="image-20220305134310271"></p>
<h3 id="11-4-3-查看路由详细信息"><a href="#11-4-3-查看路由详细信息" class="headerlink" title="11.4.3.查看路由详细信息"></a>11.4.3.查看路由详细信息</h3><p><a target="_blank" rel="noopener" href="http://localhost:9527/actuator/routes">http://localhost:9527/actuator/routes</a></p>
<h2 id="11-5-过滤器"><a href="#11-5-过滤器" class="headerlink" title="11.5.过滤器"></a>11.5.过滤器</h2><h3 id="11-5-1-功能"><a href="#11-5-1-功能" class="headerlink" title="11.5.1.功能"></a>11.5.1.功能</h3><p>负责对请求过程进行额外的处理，是请求校验过滤及服务聚合的基础</p>
<h3 id="11-5-2-过滤器的生命周期"><a href="#11-5-2-过滤器的生命周期" class="headerlink" title="11.5.2.过滤器的生命周期"></a>11.5.2.过滤器的生命周期</h3><p><img src="https://gitee.com/RMByuan/note-material/raw/master/studyImg/202203051241233.png" alt="image-20220305124059666"></p>
<h3 id="11-5-3-ZuulFilter"><a href="#11-5-3-ZuulFilter" class="headerlink" title="11.5.3.ZuulFilter"></a>11.5.3.ZuulFilter</h3><h4 id="1-过滤类型"><a href="#1-过滤类型" class="headerlink" title="1.过滤类型"></a>1.过滤类型</h4><p>pre：在请求被路由到目标服务<strong>前</strong>执行，比如权限校验、打印日志等功能</p>
<p>routing：在请求被路由到目标服务时执行</p>
<p>post：在请求被路由到目标服务后执行，比如给目标服务的响应添加头信息，收集统计数据等功能</p>
<p>error：请求在其他阶段发生错误时执行</p>
<h4 id="2-过滤顺序"><a href="#2-过滤顺序" class="headerlink" title="2.过滤顺序"></a>2.过滤顺序</h4><p>数字小的先执行（filterOrder）</p>
<h4 id="3-过滤器是否执行"><a href="#3-过滤器是否执行" class="headerlink" title="3.过滤器是否执行"></a>3.过滤器是否执行</h4><p><em>shouldFilter</em>(); 返回一个boolean值来判断该过滤器是否要执行。</p>
<h4 id="4-业务代码"><a href="#4-业务代码" class="headerlink" title="4.业务代码"></a>4.业务代码</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">PreLogFilter</span> <span class="keyword">extends</span> <span class="title">ZuulFilter</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">filterType</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;pre&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">filterOrder</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">shouldFilter</span><span class="params">()</span></span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Object <span class="title">run</span><span class="params">()</span> <span class="keyword">throws</span> ZuulException</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        RequestContext requestContext = RequestContext.getCurrentContext();</span><br><span class="line">        HttpServletRequest request = requestContext.getRequest();</span><br><span class="line">        String host = request.getRemoteHost();</span><br><span class="line">        String method = request.getMethod();</span><br><span class="line">        String uri = request.getRequestURI();</span><br><span class="line">        <span class="comment">//log.info(&quot;=====&gt; Remote host:&#123;&#125;,method:&#123;&#125;,uri:&#123;&#125;&quot;, host, method, uri);</span></span><br><span class="line">        System.out.println(<span class="string">&quot;********&quot;</span>+<span class="keyword">new</span> Date().getTime());</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="5-禁用Zuul过滤器"><a href="#5-禁用Zuul过滤器" class="headerlink" title="5.禁用Zuul过滤器"></a>5.禁用Zuul过滤器</h4><p>只需设置zuul.SendResponseFilter.post.disable=true,即可禁用该过滤器。</p>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2022/03/12/SpringCloud-Zuul%E8%B7%AF%E7%94%B1%E7%BD%91%E5%85%B3/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/SpringCloud/" rel="tag">SpringCloud</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2022/03/12/SpringCloud%20Stream%E6%B6%88%E6%81%AF%E9%A9%B1%E5%8A%A8/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            SpringCloud Stream消息驱动
          
        </div>
      </a>
    
    
      <a href="/2022/03/12/SpringCloud%E7%AC%94%E8%AE%B0/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">SpringCloud笔记</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2022
        <i class="ri-heart-fill heart_icon"></i> Yuan
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="MyBlog"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->
 
<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: ".tocbot",
    contentSelector: ".article-entry",
    headingSelector: "h1, h2, h3, h4, h5, h6",
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: "main",
    positionFixedSelector: ".tocbot",
    positionFixedClass: "is-position-fixed",
    fixedSidebarOffset: "auto",
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->
 <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script> 
<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->
 
<script src="/js/clickLove.js"></script>
 
<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->
 
<link rel="stylesheet" href="/css/clipboard.css">
 <script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>
 
<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    <div id="music">
    
    
    
    <iframe frameborder="no" border="1" marginwidth="0" marginheight="0" width="200" height="52"
        src="//music.163.com/outchain/player?type=2&id=22707008&auto=1&height=32"></iframe>
</div>

<style>
    #music {
        position: fixed;
        right: 15px;
        bottom: 0;
        z-index: 998;
    }
</style>
    
    

  </div>
</body>

</html>